//
//  FindProgramCell.swift
//  FM
//
//  Created by x on 2017/9/22.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class FindProgramCell: UICollectionViewCell {
    
    /// 图片交标
    var index:NSInteger? {
        didSet {
            iconImage.image = UIImage.init(named:"emotion"+"\(index!)")
        }
    }
    
    /// 标题
    var title:String? {
        didSet {
            titleLable.text = title;
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() -> Void {
        //1.添加子控件
        contentView.addSubview(iconImage)
        contentView.addSubview(titleLable)
        
        //2.布局子控件
        var cons:[NSLayoutConstraint] = [NSLayoutConstraint]()
        
        let dic = ["iconImage":iconImage,"titleLable":titleLable] as [String : Any]
        let space = ["left":(bounds.width-50)/2]
        
        
        cons += NSLayoutConstraint.constraints(withVisualFormat: "H:|-left-[iconImage(50)]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: space, views: dic)
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:|-left-[iconImage(50)]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: space, views: dic)
        
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:[iconImage]-5-[titleLable]", options: NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: dic)
        
        contentView.addConstraints(cons)

    }
    
    //MARK: -- 懒加载
    private lazy var iconImage:UIImageView = UIImageView.layoutImageView()
    
    private lazy var titleLable:UILabel = UILabel.lableWith(title: "", titleColor: UIColor.black, fontSize: 12)
    
}
